using System.Linq;

namespace Grain.Crm.DataMigrator.CrmServices
{
    public partial class QueryByAttribute: QueryBase
    {
        public override bool Equals(object obj)
        {
            var another = obj as QueryByAttribute;
            if(another != null)
            {
                if (another.EntityName != this.EntityName)
                    return false;

                if (this.Attributes.Length != another.Attributes.Length)
                    return false;

                if (this.Values.Length != another.Values.Length)
                    return false;

                for (int i = 0; i < this.Attributes.Length; i++)
                {
                    var value = (string) this.Attributes[i];
                    var anotherValue = (string) another.Attributes[i];
                    if (value != anotherValue)
                        return false;
                }

                for (int i = 0; i < this.Values.Length; i++)
                {
                    var value = (string) this.Values[i];
                    var anotherValue = (string) another.Values[i];
                    if (value != anotherValue)
                        return false;
                }

                return true;
            }

            return false;
        }

        public override int GetHashCode()
        {
           return this.Attributes.GetHashCode() + this.Values.GetHashCode();
        }
    }
}